#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@crane-pc>
#
# Distributed under terms of the MIT license.

"""

"""

class Solution:
    def __init__(self, a_coefficient_rep, b_coefficient_rep):
        self.a_cos = a_coefficient_rep
        self.b_cos = b_coefficient_rep

        self.len_a = len(a_coefficient_rep)
        self.len_b = len(b_coefficient_rep)

        self.len_c = len(a_coefficient_rep) + len(b_coefficient_rep) - 1
        self.c_cos = self.len_c * [0]

        # self.calc_method1()
        self.calc_method2()

    def calc_method1(self):
        for idx_c in range(self.len_c):
            coefficient = 0

            a_idx_start = max(0, idx_c - self.len_b + 1)
            a_idx_end =  min(idx_c+1, self.len_a)
            for idx_a in range(a_idx_start, a_idx_end):
                # 有可能取到idx_c
                idx_b = idx_c - idx_a
                # print("c, a, b: ", idx_c, idx_a, idx_b)
                coefficient += self.a_cos[idx_a] * self.b_cos[idx_b]
            # print()

            self.c_cos[idx_c] = coefficient

    def calc_method2(self):
        for idx_a in range(self.len_a):
            for idx_b in range(self.len_b):
                self.c_cos[idx_a + idx_b] += self.a_cos[idx_a] * self.b_cos[idx_b]


def test():
    s = Solution([-10, 1, -1, 7], [3, -6, 0, 8])
    assert [-30, 63, -9, -53, -34, -8, 56] == s.c_cos

def main():
    print("start main")
    test()

if __name__ == "__main__":
    main()
